package com.hippomeetsskunk.savanna.types.resource;

import java.util.ArrayList;
import java.util.List;

import com.hippomeetsskunk.savanna.types.goal.Goal;
import com.hippomeetsskunk.savanna.types.meta.SimObjectType;
import com.hippomeetsskunk.savanna.types.world.TimePeriod;

public class AbstractSimObject {

	@Deprecated
	private static class Reservation{
		private final Goal goal;
		private final TimePeriod period;
		
		protected Reservation(Goal goal, TimePeriod period){
			this.goal = goal;
			this.period = period;
		}
		
		public boolean isReserved(double value, double urgency, TimePeriod period){
			if (this.period.overlapsWith(period)){
				if (goal.getValue() > value && goal.getUrgency() > urgency){
					return true;
				}
			}
			return false;
		}
	}
	
	private final String name;	
	private final SimObjectType type;
	private double value;
	private double quality;
	
	private List<Reservation> reservations = new ArrayList<Reservation>();

	/**
	 * standard objects are unnamed.
	 * @param type
	 * @param value
	 * @param quality
	 */
	protected AbstractSimObject(SimObjectType type, double value, double quality){
		this(null, type, value, quality);
	}
	protected AbstractSimObject(String name, SimObjectType type, double value, double quality){
		this.name = name;
		this.type = type;
		this.value = value;
		this.quality = quality;
	}
	
	@Deprecated
	public void addReservation(Goal goal, TimePeriod period) {
		reservations.add(new Reservation(goal, period));
	}

	@Deprecated
	public boolean isReserved(double value, double urgency, TimePeriod period) {
		for(Reservation r : reservations){
			if (r.isReserved(value, urgency, period)) return true;
		}
		return false;
	}

	public SimObjectType getType() {
		return type;
	}
	
	public double getQuality() {
		return quality;
	}
	
	protected void setQuality(double quality){
		this.quality = quality;
	}
	
	public double getIntrinsicValue(){
		return value;
	}

	public String getName() {
		return name;
	}
	
	@Override
	public String toString() {
		return (name!=null) ? name : type.toString();
	}
	
}
